<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Gass_news extends CI_Controller { 
    function __construct() 
    {
    parent::__construct();
		$this->load->database();
		$this->load->library('session');
 		$this->load->helper('url');
 		$this->load->helper('form');
  	$this->auth = new stdClass;
		$this->load->library('flexi_auth');	
    if (!$this->flexi_auth->is_logged_in_via_password()) {
			$this->flexi_auth->set_error_message('请登录！', TRUE);
			$this->session->set_flashdata('message', $this->flexi_auth->get_messages());
			redirect('gass_auth');
		}
    $this->config->load('gass_conf');
		$this->load->vars('base_url', $this->config->item('base_url'));
		$this->load->vars('includes_dir', $this->config->item('includes_dir'));
		$this->load->vars('current_url', $this->uri->uri_to_assoc(1));
		$this->data = null;
		//$this->output->enable_profiler(TRUE);
	}
	  
	###++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++###	
	// 公告维护
	###++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++###	
 	/**
 	 * add_public_news ()
 	 * 编辑、上传公告内容
 	 */
  function add_public_news()
  {
		//检查用户是否拥有访问权限
		if (! $this->flexi_auth->is_privileged('news_e')){
			$this->session->set_flashdata('message', '<p class="error_msg">您没有编辑、提交公告的权限，请与系统管理员联系！</p>');
      redirect('gass_auth_teachers');
        }
   	if ($this->input->post('insert_news')){
	    $this->load->model('gass_news_model');
	    $this->gass_news_model->add_public_news();
   	}
	  $this->data['message'] = (! isset($this->data['message'])) ? $this->session->flashdata('message') : $this->data['message'];		
          // 对系统报错信息（p标签包裹的数据）进行重新处理；        
          if (!empty($this->data['message']))
          {
              $this->data['alert_message'] = $this->gass_global_model->get_alert_message($this->data['message']);   
          } 
	  $this->load->view('gass_news/new_p_news_view', $this->data);
	}		  
 	/**
 	 * manage_public_news ()
 	 * 查看所有的公告列表
 	 * 并能进行审批、编辑操作  
 	 */	  
  function manage_public_news()
  {
	  $this->load->model('gass_news_model');
	  
		//检查用户是否拥有访问权限
		if (!$this->flexi_auth->is_admin()){
			$this->session->set_flashdata('message', '<p class="error_msg">您没有浏览、审批公告的权限，请与系统管理员联系！</p>');
      redirect('gass_auth_teachers');
		}	  
		
		if ($this->input->post('update_news')) {
			$this->gass_news_model->update_public_news();
		}	  
		if ($this->input->post('search_key_words')||$this->input->post('select_news_status')) {
			$search_query = str_replace(' ','-',$this->input->post('search_key_words'));
			if(empty($search_query)) $search_query="0000";
			redirect('gass_news/manage_public_news/search_key_words/'.$search_query.'/select_news_status/'.$this->input->post('select_news_status').'/page/');
		}
	  $this->gass_news_model->get_all_public_news();
	  $this->data['newsStatusInfo'] = $this->config->item('news_status');
	  $this->data['message'] = $this->session->flashdata('message');
	  $this->load->view('gass_news/p_news_list_view', $this->data);	  	
	}
 	/**
 	 * all_public_news ()
 	 * 查看所有已通过审批的公告列表
 	 */	  	  
  function all_public_news()
  {
		/*if (! $this->flexi_auth->is_privileged('news_v')){
			$this->session->set_flashdata('message', '<p class="error_msg">您没有浏览公告的权限，请与系统管理员联系！</p>');
            redirect('gass_auth_teachers');
        }*/	
	  $this->load->model('gass_news_model');
	  $this->gass_news_model->get_all_auth_public_news();
	  $this->data['message'] = $this->session->flashdata('message');
	  $this->load->view('gass_news/all_p_news_view', $this->data);	  	
   }	  
	  
 	/**
 	 * public_news_details ()
 	 * 公告浏览页面
 	 * 审批员可在此页面进行操作，普通人只能浏览。
 	 * 参数：公告ID  
 	 */	  
  function public_news_details($pnId)
  {
	  $this->load->model('gass_news_model');
	  $this->data['publicNewsDetailInfo'] = $this->gass_news_model->get_public_news_details($pnId);
	  $this->data['message'] = $this->session->flashdata('message');
	  $this->load->view('gass_news/p_news_details_view', $this->data);	
  }	  
	  
 	/**
 	 * public_news_authorization ()
 	 * 秘书对公告进行审核
 	 * 参数：公告ID  
 	 */		  
  function public_news_authorization($pnId)
  {
	  $this->load->model('gass_news_model');
	  $this->gass_news_model->public_news_authorization($pnId);
  }		  
}
